package com.linkoog.devtools.intellij.editor;

import com.intellij.lang.Language;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.project.Project;
import com.intellij.ui.components.JBPanelWithEmptyText;
import com.intellij.util.ui.components.BorderLayoutPanel;
import com.linkoog.devtools.utils.EditorUtils;
import org.jetbrains.annotations.NotNull;

import java.awt.*;

public class EditorPanel extends JBPanelWithEmptyText {
    protected final Project project;
    protected final FileEditor fileEditor;
    public EditorPanel(@NotNull Project project, @NotNull Language language, String text) {
        super(new BorderLayout());
        this.project = project;
        fileEditor = EditorUtils.createEditor(project, language.getID(), text);
        add(fileEditor.getComponent(), BorderLayout.CENTER);
    }

    public void setEditorText(String text) {
        EditorUtils.setEditorDoc(project, fileEditor, text);
    }

    public String getEditorText() {
        return EditorUtils.getStringFromEditor(fileEditor);
    }

}
